package com.changgou.order.controller;

import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import com.changgou.goods.pojo.Sku;
import com.changgou.order.config.TokenDecode;
import com.changgou.order.pojo.MyFootMark;
import com.changgou.order.service.MyFootMarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/footmark")
public class MyFootMarkController {
    @Autowired
    private MyFootMarkService myFootMarkService;
    @Autowired
    private TokenDecode tokenDecode;

    /**
     * 添加足迹
     * @param skuId
     * @return
     */
    @PostMapping("/add")
    public Result addMyFootMark(@RequestParam("skuId") String skuId){
        MyFootMark myFootMark = new MyFootMark();
        String username = tokenDecode.getUserInfo().get("username");
        myFootMark.setBr_date(new Date());
        myFootMark.setSku_id(Long.valueOf(skuId));
        myFootMark.setUsername(username);
        myFootMarkService.addMyFootMark(myFootMark);
        return new Result(true,StatusCode.OK,"添加足迹成功");
    }

    /**
     * 我的足迹
     * @return
     */
    @GetMapping("/myfootmark")
    public Result listFootMark(){
        String username = tokenDecode.getUserInfo().get("username");
        List<Sku> skus = myFootMarkService.findByUsername(username);
        return new Result(true,StatusCode.OK,"查询成功",skus);
    }
}
